<%@ Page Language="C#" MasterPageFile="~/SMSMasterPage.master" AutoEventWireup="true"
    CodeFile="inbox.aspx.cs" Inherits="inbox" Title="Inbox" ValidateRequest="false"
    EnableEventValidation="false" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">

    <script type="text/javascript">
        var TotalChkBx;
        var Counter;

        window.onload = function() {
            //Get total no. of CheckBoxes in side the GridView.
            TotalChkBx = parseInt('<%= this.GridViewReplies.Rows.Count %>');
            //Get total no. of checked CheckBoxes in side the GridView.
            Counter = 0;
        }

        function HeaderClick(CheckBox) {
            //Get target base & child control.
            var TargetBaseControl = document.getElementById('<%= this.GridViewReplies.ClientID %>');
            var TargetChildControl = "chkSelect";

            //Get all the control of the type INPUT in the base control.
            var Inputs = TargetBaseControl.getElementsByTagName("input");

            //Checked/Unchecked all the checkBoxes in side the GridView.
            for (var n = 0; n < Inputs.length; ++n)
                if (Inputs[n].type == 'checkbox' && Inputs[n].id.indexOf(TargetChildControl, 0) >= 0)
                Inputs[n].checked = CheckBox.checked;
            //Reset Counter
            Counter = CheckBox.checked ? TotalChkBx : 0;
        }

        function ChildClick(CheckBox, HCheckBox) {
            //get target base & child control.
            var HeaderCheckBox = document.getElementById(HCheckBox);

            //Modifiy Counter;
            if (CheckBox.checked && Counter < TotalChkBx)
                Counter++;
            else if (Counter > 0)
                Counter--;

            //Change state of the header CheckBox.
            if (Counter < TotalChkBx)
                HeaderCheckBox.checked = false;
            else if (Counter == TotalChkBx)
                HeaderCheckBox.checked = true;
        }
        
        function ChildClick(CheckBox, HCheckBox) {
            //get target base & child control.
            var HeaderCheckBox = document.getElementById(HCheckBox);

            //Modifiy Counter;
            if (CheckBox.checked && Counter < TotalChkBx)
                Counter++;
            else if (Counter > 0)
                Counter--;

            //Change state of the header CheckBox.
            if (Counter < TotalChkBx)
                HeaderCheckBox.checked = false;
            else if (Counter == TotalChkBx)
                HeaderCheckBox.checked = true;
        }
    </script>

    <table width="100%">
        <tr>
            <td align="center">
                <table cellpadding="3" cellspacing="3" style="font-size: 12px;">
                    <tr>
                        <td align="left">
                            Select Number:
                        </td>
                        <td align="left">
                            <asp:DropDownList ID="ddlFromNumbers" runat="server" AutoPostBack="True" OnSelectedIndexChanged="ddlFromNumbers_SelectedIndexChanged">
                            </asp:DropDownList>
                        </td>
                    </tr>
                </table>
            </td>
        </tr>
        <tr>
            <td>
                <asp:Panel ID="panelReplies" runat="server">
                    <table width="100%" style="font-size: 12px">
                        <tr>
                            <td style="text-align: left">
                            </td>
                            <td style="text-align: right">
                                <table cellpadding="3" cellspacing="3">
                                    <tr>
                                        <td>
                                            <asp:Button ID="btnDownload" runat="server" Text="Download Inbox" OnClick="btnDownload_Click"
                                                Visible="false" />
                                        </td>
                                        <td>
                                            <asp:Button ID="btnOptOutSelected" runat="server" Visible="false" Text="Optout Selected"
                                                OnClick="btnOptOutSelected_Click" />
                                        </td>
                                        <td>
                                            <asp:Button ID="BtnDel" runat="server" OnClick="BtnDel_Click" Text="Delete Selected"
                                                Visible="false" />
                                        </td>
                                        <td>
                                            <asp:Label ID="lblPPR" runat="server" Text="Per Page Records:" Visible="false"></asp:Label>
                                        </td>
                                        <td>
                                            <asp:DropDownList ID="ddlShowRecords" runat="server" AutoPostBack="True" Visible="false"
                                                OnSelectedIndexChanged="ddlShowRecords_SelectedIndexChanged">
                                                <asp:ListItem>Select</asp:ListItem>
                                                <asp:ListItem>100</asp:ListItem>
                                                <asp:ListItem>200</asp:ListItem>
                                                <asp:ListItem>250</asp:ListItem>
                                                <asp:ListItem>500</asp:ListItem>
                                            </asp:DropDownList>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>
                                            &nbsp;
                                        </td>
                                        <td>
                                            &nbsp;
                                        </td>
                                        
                                        <td colspan="2">
                                            <asp:TextBox ID="txtSearch" runat="server" CssClass="txt_box" Height="20px" 
                                                Width="186px" MaxLength="10" Visible="false"></asp:TextBox>
                                            <cc1:FilteredTextBoxExtender ID="txtSearch_FilteredTextBoxExtender" 
                                                runat="server" Enabled="True" FilterType="Numbers" TargetControlID="txtSearch" 
                                                ValidChars="0123456789">
                                            </cc1:FilteredTextBoxExtender>
                                        </td>
                                        <td>
                                            <asp:Button ID="Button2" runat="server" Text="Search" BackColor="#135DA8" ForeColor="White"
                                                OnClick="Button2_Click" Height="26px" Visible="false" />
                                        </td>
                                    </tr>
                                </table>
                            </td>
                        </tr>
                        <tr>
                            <td colspan="2">
                                <asp:GridView ID="GridViewReplies" runat="server" AllowPaging="True" AutoGenerateColumns="False"
                                    EmptyDataText="No Data Exists!" OnPageIndexChanging="GridViewReplies_PageIndexChanging"
                                    Width="100%" AllowSorting="True" OnSorting="GridViewReplies_Sorting" BackColor="#CCCCCC"
                                    BorderColor="#999999" BorderStyle="Solid" BorderWidth="3px" CellPadding="4" CellSpacing="2"
                                    ForeColor="Black">
                                    <RowStyle BackColor="White" />
                                    <Columns>
                                        <asp:TemplateField>
                                            <HeaderTemplate>
                                                <asp:CheckBox ID="ChkAll" runat="server" onclick="javascript:HeaderClick(this);" />
                                            </HeaderTemplate>
                                            <ItemTemplate>
                                                <asp:CheckBox ID="chkSelect" runat="server" />
                                            </ItemTemplate>
                                        </asp:TemplateField>
                                        <asp:BoundField DataField="UserId" HeaderText="UserId" Visible="False" />
                                        <asp:TemplateField HeaderText="To" Visible="False">
                                            <EditItemTemplate>
                                                <asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("MsgTo") %>'></asp:TextBox>
                                            </EditItemTemplate>
                                            <ItemTemplate>
                                                <asp:Label ID="Label2" runat="server" Text='<%# Bind("MsgTo") %>'></asp:Label>
                                            </ItemTemplate>
                                        </asp:TemplateField>
                                        <asp:TemplateField HeaderText="Msg From">
                                            <EditItemTemplate>
                                                <asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("MsgFrom") %>'></asp:TextBox>
                                            </EditItemTemplate>
                                            <ItemTemplate>
                                                <asp:LinkButton ID="lbtnMsgFrom" runat="server" Text='<%# Bind("MsgFrom") %>' OnClick="lbtnMsgFrom_Click"></asp:LinkButton>
                                                <%--<asp:Label ID="Label3" runat="server" Text='<%# Bind("MsgFrom") %>'></asp:Label>--%>
                                            </ItemTemplate>
                                        </asp:TemplateField>
                                        <asp:BoundField DataField="MsgText" HeaderText="Msg From" />
                                        <asp:BoundField DataField="MsgDate" HeaderText="Date" SortExpression="MsgDate" />
                                        <asp:TemplateField HeaderText="Message Id" Visible="False">
                                            <EditItemTemplate>
                                                <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("MsgId") %>'></asp:TextBox>
                                            </EditItemTemplate>
                                            <ItemTemplate>
                                                <asp:Label ID="Label1" runat="server" Text='<%# Bind("MsgId") %>'></asp:Label>
                                            </ItemTemplate>
                                        </asp:TemplateField>
                                        <asp:TemplateField HeaderText="Delete">
                                            <ItemTemplate>
                                                <asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="~/images/Delete-icon.png"
                                                    OnClick="ImageButton1_Click" />
                                                <cc1:ConfirmButtonExtender ID="ImageButton1_ConfirmButtonExtender" runat="server"
                                                    ConfirmText="Do you really wish to delete this record?" Enabled="True" TargetControlID="ImageButton1">
                                                </cc1:ConfirmButtonExtender>
                                            </ItemTemplate>
                                        </asp:TemplateField>
                                    </Columns>
                                    <FooterStyle BackColor="#CCCCCC" />
                                    <PagerStyle BackColor="#CCCCCC" ForeColor="Black" HorizontalAlign="Left" />
                                    <SelectedRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" />
                                    <HeaderStyle BackColor="Black" Font-Bold="True" ForeColor="White" />
                                </asp:GridView>
                            </td>
                        </tr>
                    </table>
                </asp:Panel>
            </td>
        </tr>
        <tr>
            <td>
                <asp:Button ID="Button1" runat="server" Text="Button" Style="display: none;" />
                <%-- <cc1:ModalPopupExtender ID="Button1_ModalPopupExtender" runat="server" DynamicServicePath=""
                    Enabled="True" TargetControlID="Button1" BackgroundCssClass="modalBg" CancelControlID="LinkButton1"
                    PopupControlID="Panel1" OkControlID="btnSendReply">
                </cc1:ModalPopupExtender>--%>
                <cc1:ModalPopupExtender ID="Button1_ModalPopupExtender" BackgroundCssClass="modalBg"
                    runat="server" DynamicServicePath="" Enabled="True" PopupControlID="Panel1" CancelControlID="LinkButton1"
                    TargetControlID="Button1">
                </cc1:ModalPopupExtender>
                <asp:Panel ID="Panel1" runat="server" CssClass="modalPanel" Width="380px" Style="display: none;">
                    <table width="100%" style="font-size: 12px;">
                        <tr>
                            <td align="right" bgcolor="#024F79">
                                <asp:LinkButton ID="LinkButton1" runat="server" ForeColor="White">[ X ]</asp:LinkButton>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <asp:UpdatePanel runat="server" ID="UpdatePanel1">
                                    <ContentTemplate>
                                        <table width="100%">
                                            <tr>
                                                <td valign="top">
                                                    Reply Message:
                                                </td>
                                                <td>
                                                    <asp:TextBox ID="txtReplyMessage" runat="server" Height="100px" TextMode="MultiLine"
                                                        Width="250px" onkeydown="textCounter1(this,remLen4,160)" onmouseout="textCounter1(this,remLen4,160)"
                                                        onkeyup="textCounter1(this,remLen4,160)"></asp:TextBox>
                                                    <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ErrorMessage="Enter Number Here"
                                                        ControlToValidate="txtReplyMessage" ValidationGroup="number">*</asp:RequiredFieldValidator>
                                                    <cc1:ValidatorCalloutExtender ID="RequiredFieldValidator3_ValidatorCalloutExtender"
                                                        runat="server" Enabled="True" TargetControlID="RequiredFieldValidator3">
                                                    </cc1:ValidatorCalloutExtender>
                                                    <br />
                                                    <table>
                                                        <tr>
                                                            <td>
                                                                <input maxlength="3" name="remLen4" readonly="readonly" size="3" type="text" value="160"
                                                                    style="width: 27px" />
                                                            </td>
                                                            <td>
                                                                chars left
                                                            </td>
                                                            <td>
                                                                &nbsp;
                                                            </td>
                                                        </tr>
                                                    </table>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td>
                                                    &nbsp;
                                                </td>
                                                <td>
                                                    <asp:UpdatePanel ID="updschedulemsg" runat="server">
                                                        <ContentTemplate>
                                                            <%--<asp:RadioButtonList ID="RBL_sendsms" runat="server" AutoPostBack="True" OnSelectedIndexChanged="RBL_sendsms_SelectedIndexChanged">
                                                                <asp:ListItem Selected="True">Send Message Now</asp:ListItem>
                                                                <asp:ListItem>Schedule Message</asp:ListItem>
                                                            </asp:RadioButtonList>--%>
                                                            <asp:Panel ID="Panel12" runat="server" CssClass="modalPanel" Height="80px" Width="260px">
                                                                <legend style="color: #333333"><b>Schedule Date Time</b></legend>
                                                                <table width="100%">
                                                                    <tr>
                                                                        <td align="left" style="width: 59px">
                                                                            &nbsp;Date:
                                                                        </td>
                                                                        <td align="left">
                                                                            <asp:TextBox ID="txtDate" runat="server" autocomplete="off" Width="119px"></asp:TextBox>
                                                                            <cc1:CalendarExtender ID="txtDate_CalendarExtender" runat="server" Enabled="True"
                                                                                TargetControlID="txtDate">
                                                                            </cc1:CalendarExtender>
                                                                        </td>
                                                                    </tr>
                                                                    <tr>
                                                                        <td align="left" style="width: 59px">
                                                                            &nbsp;Time:
                                                                        </td>
                                                                        <td>
                                                                            <table>
                                                                                <tr>
                                                                                    <td style="height: 26px">
                                                                                        <asp:DropDownList ID="DropDownListHour" runat="server" Style="font-family: Arial, Helvetica, sans-serif;
                                                                                            font-size: small; color: #666666">
                                                                                            <asp:ListItem>1</asp:ListItem>
                                                                                            <asp:ListItem>2</asp:ListItem>
                                                                                            <asp:ListItem>3</asp:ListItem>
                                                                                            <asp:ListItem>4</asp:ListItem>
                                                                                            <asp:ListItem>5</asp:ListItem>
                                                                                            <asp:ListItem>6</asp:ListItem>
                                                                                            <asp:ListItem>7</asp:ListItem>
                                                                                            <asp:ListItem>8</asp:ListItem>
                                                                                            <asp:ListItem>9</asp:ListItem>
                                                                                            <asp:ListItem>10</asp:ListItem>
                                                                                            <asp:ListItem>11</asp:ListItem>
                                                                                            <asp:ListItem>12</asp:ListItem>
                                                                                        </asp:DropDownList>
                                                                                    </td>
                                                                                    <td style="height: 26px">
                                                                                        <asp:DropDownList ID="DropDownListMinute" runat="server" Style="font-family: Arial, Helvetica, sans-serif;
                                                                                            font-size: small; color: #666666">
                                                                                            <asp:ListItem Value="00">00</asp:ListItem>
                                                                                            <asp:ListItem Value="01">01</asp:ListItem>
                                                                                            <asp:ListItem Value="02">02</asp:ListItem>
                                                                                            <asp:ListItem Value="03">03</asp:ListItem>
                                                                                            <asp:ListItem Value="04">04</asp:ListItem>
                                                                                            <asp:ListItem Value="05">05</asp:ListItem>
                                                                                            <asp:ListItem Value="06">06</asp:ListItem>
                                                                                            <asp:ListItem Value="07">07</asp:ListItem>
                                                                                            <asp:ListItem Value="08">08</asp:ListItem>
                                                                                            <asp:ListItem Value="09">09</asp:ListItem>
                                                                                            <asp:ListItem Value="10">10</asp:ListItem>
                                                                                            <asp:ListItem Value="11">11</asp:ListItem>
                                                                                            <asp:ListItem Value="12">12</asp:ListItem>
                                                                                            <asp:ListItem Value="13">13</asp:ListItem>
                                                                                            <asp:ListItem Value="14">14</asp:ListItem>
                                                                                            <asp:ListItem Value="15">15</asp:ListItem>
                                                                                            <asp:ListItem Value="16">16</asp:ListItem>
                                                                                            <asp:ListItem Value="17">17</asp:ListItem>
                                                                                            <asp:ListItem Value="18">18</asp:ListItem>
                                                                                            <asp:ListItem Value="19">19</asp:ListItem>
                                                                                            <asp:ListItem Value="20">20</asp:ListItem>
                                                                                            <asp:ListItem Value="23">21</asp:ListItem>
                                                                                            <asp:ListItem Value="22">22</asp:ListItem>
                                                                                            <asp:ListItem Value="23">23</asp:ListItem>
                                                                                            <asp:ListItem Value="24">24</asp:ListItem>
                                                                                            <asp:ListItem Value="25">25</asp:ListItem>
                                                                                            <asp:ListItem Value="26">26</asp:ListItem>
                                                                                            <asp:ListItem Value="27">27</asp:ListItem>
                                                                                            <asp:ListItem Value="28">28</asp:ListItem>
                                                                                            <asp:ListItem Value="29">29</asp:ListItem>
                                                                                            <asp:ListItem Value="30">30</asp:ListItem>
                                                                                            <asp:ListItem Value="31">31</asp:ListItem>
                                                                                            <asp:ListItem Value="32">32</asp:ListItem>
                                                                                            <asp:ListItem Value="33">33</asp:ListItem>
                                                                                            <asp:ListItem Value="34">34</asp:ListItem>
                                                                                            <asp:ListItem Value="35">35</asp:ListItem>
                                                                                            <asp:ListItem Value="36">36</asp:ListItem>
                                                                                            <asp:ListItem Value="37">37</asp:ListItem>
                                                                                            <asp:ListItem Value="38">38</asp:ListItem>
                                                                                            <asp:ListItem Value="39">39</asp:ListItem>
                                                                                            <asp:ListItem Value="40">40</asp:ListItem>
                                                                                            <asp:ListItem Value="41">41</asp:ListItem>
                                                                                            <asp:ListItem Value="42">42</asp:ListItem>
                                                                                            <asp:ListItem Value="43">43</asp:ListItem>
                                                                                            <asp:ListItem Value="44">44</asp:ListItem>
                                                                                            <asp:ListItem Value="45">45</asp:ListItem>
                                                                                            <asp:ListItem Value="46">46</asp:ListItem>
                                                                                            <asp:ListItem Value="47">47</asp:ListItem>
                                                                                            <asp:ListItem Value="48">48</asp:ListItem>
                                                                                            <asp:ListItem Value="49">49</asp:ListItem>
                                                                                            <asp:ListItem Value="50">50</asp:ListItem>
                                                                                            <asp:ListItem Value="51">51</asp:ListItem>
                                                                                            <asp:ListItem Value="52">52</asp:ListItem>
                                                                                            <asp:ListItem Value="53">53</asp:ListItem>
                                                                                            <asp:ListItem Value="54">54</asp:ListItem>
                                                                                            <asp:ListItem Value="55">55</asp:ListItem>
                                                                                            <asp:ListItem Value="56">56</asp:ListItem>
                                                                                            <asp:ListItem Value="57">57</asp:ListItem>
                                                                                            <asp:ListItem Value="58">58</asp:ListItem>
                                                                                            <asp:ListItem Value="59">59</asp:ListItem>
                                                                                        </asp:DropDownList>
                                                                                    </td>
                                                                                    <td style="height: 26px">
                                                                                        <asp:DropDownList ID="ddlAMPM" runat="server">
                                                                                            <asp:ListItem>AM</asp:ListItem>
                                                                                            <asp:ListItem>PM</asp:ListItem>
                                                                                        </asp:DropDownList>
                                                                                    </td>
                                                                                </tr>
                                                                            </table>
                                                                        </td>
                                                                    </tr>
                                                                    <%--<tr>
                                                                        <td align="left" style="width: 59px" colspan="2">
                                                                            <table style="width: 195px">
                                                                                <tr>
                                                                                    <td align="left">
                                                                                        Time Zone:
                                                                                    </td>
                                                                                    <td>
                                                                                        <asp:DropDownList ID="ddlTimeZone" runat="server">
                                                                                            <asp:ListItem>Time Zone</asp:ListItem>
                                                                                            <asp:ListItem Value="-08:00">PST</asp:ListItem>
                                                                                            <asp:ListItem Value="-07:00">MST</asp:ListItem>
                                                                                            <asp:ListItem Value="-06:00">CST</asp:ListItem>
                                                                                            <asp:ListItem Value="-05:00">EST</asp:ListItem>
                                                                                        </asp:DropDownList>
                                                                                    </td>
                                                                                </tr>
                                                                            </table>
                                                                        </td>
                                                                    </tr>--%>
                                                                </table>
                                                            </asp:Panel>
                                                        </ContentTemplate>
                                                    </asp:UpdatePanel>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td>
                                                    &nbsp;
                                                </td>
                                                <td>
                                                    <asp:Label ID="lblmsg" runat="server"></asp:Label>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td>
                                                </td>
                                                <td>
                                                    <asp:Button ID="btnSendReply" runat="server" OnClick="btnSendReply_Click" Text="Send Reply"
                                                        ValidationGroup="number" />
                                                </td>
                                            </tr>
                                        </table>
                                    </ContentTemplate>
                                </asp:UpdatePanel>
                            </td>
                        </tr>
                    </table>
                </asp:Panel>
            </td>
        </tr>
    </table>
</asp:Content>
